<?php


namespace app\common\model;

use think\Db;
use think\Exception;
use think\Model;

class UserQualifications extends Model
{
    // 表名,不含前缀
    protected $name = 'user_qualifications';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    protected $type = [
        'createtime' => 'datetime:Y-m-d H:i:s',
        'updatetime' => 'datetime:Y-m-d H:i:s',
    ];

    /**
     * @var null|static 实例对象
     */
    protected static $instance = null;

    /**
     * 获取示例
     * @param array $options 实例配置
     * @return static
     */
    public static function instance($options = [])
    {
        if (is_null(self::$instance)) self::$instance = new self($options);

        return self::$instance;
    }

    /**
     * @throws
     * */
    public function submit()
    {
        $primary_id = [];
        if (!empty($this->data['primary_id'])) {
            $primary_id['id'] = $this->data['primary_id'];
        }
        $save['user_id'] = $this->data['user_id'];
        if (!empty($this->data['qualifications_name'])) {
            $save['name'] = $this->data['qualifications_name'];
        }

        if (!empty($this->data['qualifications_path']) && !empty($this->data['path_file_name'])) {
            $save['path'] = $this->data['qualifications_path'];
            $save['path_file_names'] = $this->data['path_file_name'];
        }
        $response = $this->allowField(true)->save($save, array_filter($primary_id));
        if ($response) {
            return true;
        }
        throw new Exception('保存失败');
    }
}